/*
 * @Author: 江舟 jijiangzhou@recycloud.cn
 * @Date: 2024-07-05 11:05:31
 * @LastEditors: 江舟 jijiangzhou@recycloud.cn
 * @LastEditTime: 2024-07-05 11:10:02
 * @FilePath: \vite-project\src\store\message.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { countWaitReadInbox } from '@/apis/message';
import { create } from 'zustand';

type State = {
	waitReadCount: number;
};

type Action = {
	getUnreadMessage: () => void;
	cleartMessage: () => void;
};

export const useMessageStore = create<State & Action>((set, get) => ({
	waitReadCount: 0,
	getUnreadMessage: async () => {
		let res = await countWaitReadInbox({});
		set(() => ({
			waitReadCount: res?.waitReadCount || 0,
		}));
	},
	cleartMessage: () => set(() => ({ waitReadCount: 0 })),
}));
